//
//  MyScrollView.m
//  王宇先_09
//
//  Created by wyx on 16/3/21.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "MyScrollView.h"

@implementation MyScrollView

- (instancetype)initWithFrame:(CGRect)frame withImages:(NSArray<UIImage *> *)images delegate:(id)delegate{
    self = [super initWithFrame:frame];
    if (self) {
        [self scrollWithFrame:frame withImages:images delegate:delegate];
    }
    return self;
}

- (void)scrollWithFrame:(CGRect)frame withImages:(NSArray<UIImage *> *)images delegate:(id)delegate{
    //设置contentSize
    self.contentSize = CGSizeMake(frame.size.width * images.count, frame.size.height);
    //创建小的ScrollView
    for (int i = 0; i < images.count; i++){
        UIScrollView *ScrollViewOfSmall = [[UIScrollView alloc] initWithFrame:CGRectMake(frame.size.width * i, 0, frame.size.width, frame.size.height)];
        [self addSubview:ScrollViewOfSmall];
        [ScrollViewOfSmall release];
        
        ScrollViewOfSmall.minimumZoomScale = 0.5;
        ScrollViewOfSmall.maximumZoomScale = 2;
        ScrollViewOfSmall.delegate = delegate;
        
        //创建ImageView
        UIImageView *imageView = [[UIImageView alloc] initWithImage:images[i]];
        imageView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
        [ScrollViewOfSmall addSubview:imageView];
        [imageView release];
    }
    //开启翻页效果
    self.pagingEnabled = YES;
    //开启回弹效果
    self.bounces = YES;
    //滑动指示器
    self.showsHorizontalScrollIndicator = YES;
    
}

@end
